package com.shine.icis.action;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.esim.struts.webutil.SessionParam;
import com.shine.icis.blo.IDeptInfoService;
import com.shine.icis.config.SysConstants;
import com.shine.icis.dto.DeptInfo;
import com.shine.icis.exception.ICISException;
import com.shine.icis.util.EFRameInf;

/**
 * 基础信息管理->证券公司营业部信息文件
 * @author zsy
 *
 */
public class DeptInfoAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7638121893867812633L;
	
	private IDeptInfoService deptInfoService;
	//input param
	private int pageNo;
	private int pageSize;
	private String oldDeptCode;
	private String oldIntDeptCode;
	
	private String deptCode;//证券公司营业部代码
	private String deptName;//证券公司营业部名称
	private String intDeptCode;//证券公司营业部内部代码
	private String occurDate;//
	
	//output param
	private ListPage<DeptInfo> deptInfoPage;
	
	public void setDeptInfoService(IDeptInfoService deptInfoService) {
		this.deptInfoService = deptInfoService;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setOldDeptCode(String oldDeptCode) {
		this.oldDeptCode = oldDeptCode;
	}

	public void setOldIntDeptCode(String oldIntDeptCode) {
		this.oldIntDeptCode = oldIntDeptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public void setIntDeptCode(String intDeptCode) {
		this.intDeptCode = intDeptCode;
	}

	public void setOccurDate(String occurDate) {
		this.occurDate = occurDate;
	}

	
	public ListPage<DeptInfo> getDeptInfoPage() {
		return deptInfoPage;
	}

	/**
	 * 转到查询页面
	 * @return
	 */
	public String initQueryDeptInfo() {
//		companyCode = companyInfoService.getCompanyCode();
		return success();
	}
	
	/**
	 * 查询
	 * @return
	 */
	public String queryDeptInfo() {
		QueryParameters qp = new QueryParameters();
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		try {
			deptInfoPage = deptInfoService.getDeptInfoPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	
	/**
	 * 新增
	 * @return
	 */
	public String addDeptInfo() {
		if (deptCode == null || deptCode.trim().equals("")
				|| deptName == null || deptName.trim().equals("")
				|| intDeptCode == null || intDeptCode.trim().equals("")
				|| occurDate == null || occurDate.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			occurDate = occurDate.trim().replaceAll("-", "");
			deptInfoService.addDeptInfo(deptCode, deptName, intDeptCode, occurDate);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "增加证券公司营业部信息营业部代码为[" + deptCode + "]", success);
		}
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String modifyDeptInfo() {
		if (oldDeptCode == null || oldDeptCode.trim().equals("")
				|| oldIntDeptCode == null || oldIntDeptCode.trim().equals("")
				|| deptCode == null || deptCode.trim().equals("")
				|| deptName == null || deptName.trim().equals("")
				|| intDeptCode == null || intDeptCode.trim().equals("")
				|| occurDate == null || occurDate.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			occurDate = occurDate.trim().replaceAll("-", "");
			deptInfoService.modifyDeptInfo(oldDeptCode, oldIntDeptCode, deptCode, deptName, intDeptCode, occurDate);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "修改证券公司营业部信息营业部代码为[" + oldDeptCode + "]", success);
		}
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String deleteDeptInfo() {
		if (deptCode == null || deptCode.trim().equals("")
				|| intDeptCode == null || intDeptCode.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			deptInfoService.deleteDeptInfo(deptCode, intDeptCode);
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "删除证券公司营业部信息营业部代码为[" + deptCode + "]", success);
		}
	}

}
